package Servlet;

import pojo.User;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.IOException;
import java.util.*;

@WebServlet("/ManageServlet")
public class ManageServlet extends HttpServlet {
    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
//       先从Request取，若无, 则从Session取
//        HttpSession session = req.getSession();
//        session.setAttribute("username","张三");
//        req.setAttribute("username","李四");
//        转发
//        req.getRequestDispatcher("manage.jsp").forward(req,resp);
//        重定向
//        resp.sendRedirect("manage.jsp");

        req.setAttribute("user",new User("张三","男"));

        List<String> list = new ArrayList<>();
        Collections.addAll(list,"李四","王五","沈六");
        req.setAttribute("list",list);

        Map<String,String> map = new HashMap<>();
        map.put("name","张三");
        map.put("sex","男");
        req.setAttribute("map",map);

        req.getRequestDispatcher("manage.jsp").forward(req,resp);
    }
}
